#include "BattleLineFrameListener.h"

bool CBattleLineFrameListener::frameStarted(const FrameEvent& evt)
{
	mMouse->capture();
	mKeyboard->capture();

	//mouse
	bool currMouse = mMouse->getMouseState().buttonDown(OIS::MB_Left);
	if (currMouse && ! mMouseDown)
	{
		Light *light = mSceneMgr->getLight("Light1");
		light->setVisible(! light->isVisible());
	} // if
	mMouseDown = currMouse;

	if (mMouse->getMouseState().buttonDown(OIS::MB_Right))
	{
		mCamNode->yaw(Degree(-mRotate * mMouse->getMouseState().X.rel), Node::TS_WORLD);
		mCamNode->pitch(Degree(-mRotate * mMouse->getMouseState().Y.rel), Node::TS_LOCAL);
	}

	//key
	if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
		return false;

	mToggle -= evt.timeSinceLastFrame;
	if ((mToggle < 0.0f ) && mKeyboard->isKeyDown(OIS::KC_1))
	{
		mToggle = 0.5f;
		mCamera->getParentSceneNode()->detachObject(mCamera);
		mCamNode = mSceneMgr->getSceneNode("CamNode1");
		mCamNode->attachObject(mCamera);
	}
	else if ((mToggle < 0.0f) && mKeyboard->isKeyDown(OIS::KC_2))
	{
		mToggle = 0.5f;
		mCamera->getParentSceneNode()->detachObject(mCamera);
		mCamNode = mSceneMgr->getSceneNode("CamNode2");
		mCamNode->attachObject(mCamera);
	}

	Vector3 transVector = Vector3::ZERO;
	if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
		transVector.z -= mMove;
	if (mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
		transVector.z += mMove;
	if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
		transVector.x -= mMove;
	if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
		transVector.x += mMove;
	if (mKeyboard->isKeyDown(OIS::KC_PGUP) || mKeyboard->isKeyDown(OIS::KC_Q))
		transVector.y += mMove;
	if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
		transVector.y -= mMove;
	mCamNode->translate(transVector * evt.timeSinceLastFrame, Node::TS_LOCAL);

	//return CBaseFrameListener::frameStarted(evt);
}

bool CBattleLineFrameListener::frameEnded(const FrameEvent& evt)
{
	return CBaseFrameListener::frameEnded(evt);
}
